package fleditor.common
{
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.system.ApplicationDomain;
	import flash.system.LoaderContext;
	
	import fleditor.core.loader.BaseLoader;
	import fleditor.core.loader.LoaderFactory;
	import fleditor.core.loader.LoaderType;

	/**
	 * 地图资源库加载 
	 * @author Devin
	 * 
	 */	
	public class MapAssetLibLoad extends EventDispatcher
	{
		private var _loader:BaseLoader;
		private var _path:String;
		private var _assetLib:*;
		
		/**
		 * 地图资源库加载  
		 * @param path 资源库物理路径
		 * 
		 */
		public function MapAssetLibLoad(path:String)
		{
			_path=path;
			var loaderContext:LoaderContext=new LoaderContext();
			loaderContext.allowLoadBytesCodeExecution=true;
			loaderContext.applicationDomain=ApplicationDomain.currentDomain;
			_loader=LoaderFactory.Instance.createLoader(LoaderType.Loader, path, true, onLoadAssetCallBack, 3, loaderContext);
		}

		/**
		 * 资源库数据
		 * @return 
		 * 
		 */		
		public function get assetLib():*
		{
			return _assetLib;
		}

		/**
		 * 资源库数据
		 * @return 
		 * 
		 */
		public function set assetLib(value:*):void
		{
			_assetLib = value;
		}

		/**
		 * 地图资源库加载类
		 * @return
		 */		
		public function get loader():BaseLoader
		{
			return _loader;
		}

		public function set loader(value:BaseLoader):void
		{
			_loader = value;
		}

		/**
		 * 加载成功 
		 * @param baseLoader
		 * 
		 */		
		private function onLoadAssetCallBack(baseLoader:BaseLoader):void
		{
			_assetLib=baseLoader.data;
			dispatchEvent(new Event(Event.COMPLETE));
		}

		/**
		 *资源库路径 
		 * @return String
		 * 
		 */		
		public function get path():String
		{
			return _path;
		}

		/**
		 *资源库路径 
		 * 
		 */	
		public function set path(value:String):void
		{
			_path = value;
		}
		
		/**
		 *资源释放 
		 * 
		 */		
		public function dispose():void
		{
			if(_loader) _loader.dispose();
			_loader=null;
		}
	}
}